import { Component } from "react";
import PubSub from "pubsub-js";
import A from './components/A'
import B from './components/B'


/*
总结：
publish:发布者
    // 异步执行
    pubSub.publish("消息的名字","消息的内容");
    // 同步执行
    pubSub.publishSync("消息的名字","消息的内容");
subscribe:订阅者
    // 订阅多次
    pubSub.subscribe("消息的名字",("消息的名字","消息的内容")=>{})
    // 订阅一次
    pubSub.subscribeOnce("消息的名字",("消息的名字","消息的内容")=>{})
unsubscribe:取消订阅
    pubSub.unsubscribe("消息的名字");
*/

class App extends Component {
    render() {
        return (
            <div>
                <A></A>
                <B></B>
            </div>
        )
    }

    componentDidMount() {
        PubSub.subscribeOnce('one', (msgName, a) => {
            console.log('App', msgName, a)
        })
    }
}








export default App